﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcContrib.Pagination;
using Project.DAL.Repository;

namespace Project.WebUI.Areas.Admin.Controllers
{
    public class BetController : Controller
    {
        #region "private"
        private readonly IUserRepository _userRepository;
        private readonly IDepositRepository _depositRepository;
        private readonly IWithDrawRepository _withDrawRepository;
        private readonly IUserService _userService;
        private readonly ICountryRepository _countryRepository;
        private readonly IContactRepository _contactRepository;
        private readonly IBetRepository _betRepository;
        private readonly IStoreSecureRepositoty _storeSecureRepositoty;
        
        public BetController(
            IUserRepository userRepository,
            IDepositRepository depositRepository,
            IWithDrawRepository withDrawRepository,
            IUserService userService,
            ICountryRepository countryRepository,
            IContactRepository contactRepository, 
            IBetRepository betRepository,
            IStoreSecureRepositoty storeSecureRepositoty)
        {
            _userRepository = userRepository;
            _depositRepository = depositRepository;
            _withDrawRepository = withDrawRepository;
            _userService = userService;
            _countryRepository = countryRepository;
            _contactRepository = contactRepository;
            _betRepository = betRepository;
            _storeSecureRepositoty = storeSecureRepositoty;
        }
        #endregion        

        #region Index
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region "LoadAjaxContent"       
        public ActionResult LoadAjax(int page)
        {
            var listBet = _betRepository
                .GetMany(null, d => d.OrderByDescending(t => t.MaxBet)
                                        .ThenBy(t => t.Status), "User,Match");
            ViewBag.page = page;
            ViewBag.result = listBet.Count();
            
            if (page == 1)
            {
                ViewBag.start = 0;
            }
            else
            {
                ViewBag.start = (page - 1) * 10;
            }

            return PartialView("_MainContent", listBet.AsPagination(page, 10));
        }
        #endregion

        #region UpdateStatus
        public ActionResult UpdateStatus(int id, int status)
        {
            var wd = _betRepository.GetById(id);
            if (status == 1)
            {
                wd.Status = false;
                _betRepository.SaveChanges();
                ViewBag.status = false;
                ViewBag.id = id;
                ViewBag.controller = "Bet";
                return PartialView("_UpdateStatus");
            }
            wd.Status = true;
            _betRepository.SaveChanges();
            ViewBag.status = true;
            ViewBag.id = id;
            ViewBag.controller = "Bet";
            return PartialView("_UpdateStatus");
        }
        #endregion

    }
}
